<?php
/**
 * Created by PhpStorm.
 * User: silenceper
 * Date: 2016/11/28
 * Time: 上午10:39
 */

namespace common\repositories\myhtsq;


use common\entities\myhtsq\ProjectContactChangeLogEntity;
use common\repositories\BaseRepository;
use common\support\StringHelper;

class ProjectContactChangeLogRepository extends BaseRepository
{
    /**
     * 增加log
     * @param $data
     * @return bool
     */
    public function addLog($data)
    {
        $entity = new ProjectContactChangeLogEntity();
        $entity->setAttributes($data);
        $entity->id = StringHelper::uuid();
        $entity->created_by = \Yii::$app->user->identity->userguid;
        $entity->updated_at = date("Y-m-d H:i:s");
        $entity->created_at = date("Y-m-d H:i:s");
        return $entity->save();
    }

    /**
     * 根据项目获取log
     * @param $orgId
     * @param $projectId
     * @return array|\yii\db\ActiveRecord[]
     */
    public function getLogByProject($orgId, $projectId)
    {
        return ProjectContactChangeLogEntity::find()
            ->where(["org_id" => $orgId, "project_id" => $projectId])
            ->orderBy("created_at desc")->all();
    }
}